package com.hr.controller.admin;

import com.hr.domain.dto.ClientDTO;
import com.hr.domain.query.OrderPageParams;
import com.hr.domain.query.OrderPageResult;
import com.hr.domain.vo.ClientOrderVO;
import com.hr.service.OrderService;
import com.hr.utils.Result;
import com.hr.utils.UserContext;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/order")
@Tag(name = "后台订单信息管理")
@Slf4j
@AllArgsConstructor
public class OrderController {

    private final OrderService orderService;

    /**
     * 分页获取订单列表
     *
     * @param queryParams
     * @return orderPageResult
     */
    @GetMapping("/page")
    @Operation(summary = "分页获取订单列表")
    public Result getOrderPageList(OrderPageParams queryParams) {
        log.info("分页获取订单列表");
        OrderPageResult orderPageResult = orderService.getOrderPageList(queryParams);
        return Result.success(orderPageResult);
    }

    /**
     * 更新订单状态
     *
     * @param id
     * @param status
     * @return 订单状态:0:待支付,1:已支付，2：已取消
     */
    @PutMapping("/updateStatus")
    @Operation(summary = "更新订单状态")
    public Result updateOrderStatus(@RequestParam("id") Long id,
                                    @RequestParam("status") Integer status) {
        log.info("更新订单状态");
        String msg = orderService.updateOrderStatus(id, status);
        return Result.success(msg);
    }

    /**
     * 获取单个用户的所有订单信息
     *
     * @return
     */
    @GetMapping("/details")
    @Operation(summary = "获取单个用户的所有订单信息")
    public Result getOrderDetails(ClientDTO clientDTO) {
        log.info("获取单个用户的所有订单信息");
        List<ClientOrderVO> orderDetailsList = orderService.getOrderDetails(clientDTO);
        if (orderDetailsList == null) {
            return Result.error("没有该用户订单信息");
        }
        return Result.success(orderDetailsList);
    }



}
